<?php
namespace Admin\Controller;
use Admin\Controller;
/**
 * 示例管理
 */
class MessageController extends BaseController
{
    /**
     * 列表
     * @return [type] [description]
     */
    public function index($key="")
    {
        $mobile = I('mobile');

        $banners    = M('message'); // 实例化User对象
        $where['status']      = array('gt',-1);
        if(!empty($mobile)){
            $where['mobile']  = array('like',"%$mobile%");
        }
        $count      = $banners->where($where)->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $this->page = $Page->show();// 分页显示输出
        $this->list = $banners->where($where)->order(array('status' => 'desc', 'id' => 'desc'))->limit($Page->firstRow.','.$Page->listRows)->select();

        $this->display(); // 输出模板
    }

    /**
     * 更新
     * @param  [type] $id [分类ID]
     * @return [type]     [description]
     */
    public function update()
    {
        //默认显示添加表单
        if (IS_POST) {
            $id = I('post.message_id');

            $data['status'] = I('post.status');

            if (M('message')->where(array('id' => $id))->save($data)) {
                $this->success("操作成功", U('message/index'));
            } else {
                $this->error("操作失败");
            }

        }else{
            $this->info = M('message')->find(I('id'));

            $this->display();
        }
    }
    /**
     * 删除分类
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function delete($id)
    {
        $data['status'] = -1;
        if (M('message')->where(array('id' => $id))->save($data)) {
            $this->success("删除成功");
        } else {
            $this->error("删除失败");
        }
    }
}
